//
//  JOMainViewController.m
//  taxin_song
//
//  Created by song on 16/1/17.
//  Copyright © 2016年 song. All rights reserved.
//

#import "JOMainViewController.h"
#import "Utils.h"

@interface JOMainViewController ()

@property(nonatomic, strong) UIImageView *contentView;

@property(nonatomic ,strong) UIImageView *iconView;

@property(nonatomic ,strong)UILabel *nameLabel;

@property(nonatomic ,strong)UIImageView *leiView;

@property(nonatomic ,strong)UIButton *findbtn;

@property(nonatomic ,strong)UIButton *sharebtn;

@property(nonatomic ,strong)UIButton *userbtn;

@property(nonatomic ,strong)UIButton *netbtn;


@end


@implementation JOMainViewController


-(void)viewDidLoad
{
    
    UIImageView *superView =[[UIImageView  alloc] initWithImage:[UIImage imageNamed:@"index_main"]];
    superView.frame = self.view.frame;
    _contentView =superView;
    [self.view addSubview:superView];
    
    [self setupSubViews];
    [self setupNav];
    [self setlayout];
    
}


-(void)setupNav
{
    self.navigationItem.title = @"他信宝";
}


-(void)setupSubViews
{
    UIImage *img = [UIImage imageNamed:@"shareImg"];
    UIImage *newimg =[Utils cutImageToIcon:img];
    _iconView = [[UIImageView alloc] initWithImage:newimg];
    [_contentView addSubview:_iconView];
    
    _nameLabel = [[UILabel alloc] init];
    [_nameLabel setText:@"helloword"];
    [_contentView addSubview:_nameLabel];
    
    _leiView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lei"]];
    [_contentView addSubview:_leiView];
    
    
    _findbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_findbtn setImage:[UIImage imageNamed:@"index_-viewreport_btn"] forState:UIControlStateNormal];
    [_contentView addSubview:_findbtn];
    
    _sharebtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_sharebtn setImage:[UIImage imageNamed:@"index_-sharereport_btn"] forState:UIControlStateNormal];
    [_contentView addSubview:_sharebtn];
    
    _userbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_userbtn setTitle:@"个人信息补全" forState:UIControlStateNormal];
//    [_userbtn setBackgroundColor:[UIColor yellowColor]];
    [_contentView addSubview:_userbtn];
    
    _netbtn = [UIButton buttonWithType:UIButtonTypeCustom];
     [_netbtn setTitle:@"互联网信息补全" forState:UIControlStateNormal];
//    [_netbtn setBackgroundColor:[UIColor redColor]];
    [_contentView addSubview:_netbtn];
}

-(void)setlayout
{
    
    int Main_W = _contentView.frame.size.width;
    int Main_H = _contentView.frame.size.height;
    for(UIView *view  in self.contentView.subviews) {view.translatesAutoresizingMaskIntoConstraints =NO ;}
    NSDictionary *views = NSDictionaryOfVariableBindings(_iconView ,_nameLabel ,_leiView , _findbtn , _sharebtn ,_userbtn ,_netbtn);
    
    // 设置各自的尺寸
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_iconView(80)]" options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_iconView(80)]" options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_nameLabel(20)]" options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_nameLabel(50)]" options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_leiView(200)]" options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_leiView(200)]" options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_findbtn(40)]" options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_findbtn(40)]" options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_sharebtn(40)]" options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_sharebtn(40)]" options:0 metrics:nil views:views]];
     [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_userbtn(40)]" options:0 metrics:nil views:views]];
     [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_netbtn(40)]" options:0 metrics:nil views:views]];
    
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat:@"H:[_userbtn(%d)]",Main_W/2]    options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat:@"H:[_netbtn(%d)]",Main_W/2]   options:0 metrics:nil views:views]];
    
    // 设置 每个控件的水平间距
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-100-[_iconView]-10-[_nameLabel]-10-[_leiView]" options:NSLayoutFormatAlignAllCenterX metrics:nil views:views]];
    
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_leiView]-[_findbtn]" options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_leiView]-[_sharebtn]" options:0 metrics:nil views:views]];
    
    //设置两个空间距左边和右边的距离
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-40-[_findbtn]" options:0 metrics:nil views:views]];
    [_contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_sharebtn]-40-|" options:0 metrics:nil views:views]];
    
    
    [_contentView addConstraint:[NSLayoutConstraint constraintWithItem:_iconView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_contentView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [_contentView addConstraint:[NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_contentView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    
    [_contentView addConstraint:[NSLayoutConstraint constraintWithItem:_leiView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_contentView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    
    [_contentView addConstraint:[NSLayoutConstraint constraintWithItem:_userbtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:_contentView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    
    [_contentView addConstraint:[NSLayoutConstraint constraintWithItem:_netbtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:_contentView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    
    [_contentView addConstraint:[NSLayoutConstraint constraintWithItem:_userbtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_contentView attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    
    [_contentView addConstraint:[NSLayoutConstraint constraintWithItem:_netbtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:_contentView attribute:NSLayoutAttributeRight multiplier:1 constant:0]];
}



@end
